package cn.bonoon.kernel.web.html.form;

import cn.bonoon.handler.impl.StandardAutoManager;
import cn.bonoon.kernel.descriptors.UIClassDescriptor;
import cn.bonoon.kernel.descriptors.UIPropertyAccessor;
import cn.bonoon.kernel.web.annotations.form.FormInsert;
import cn.bonoon.kernel.web.annotations.form.PropertyEditor;
import cn.bonoon.kernel.web.annotations.form.PropertyInsert;

public final class StandardInsertBuilder extends AbstractEditableBuilder{
	
	public StandardInsertBuilder(UIClassDescriptor objectDescriptor, StandardAutoManager manager) {
		super(objectDescriptor, manager);
	}
	
	@Override
	protected void init() {
		super.init();
		FormInsert fd = uiDescriptor.getAnnotation(FormInsert.class);
		if(null != fd){
			if(fd.value() > 0){
				column= fd.value();
			}
			if(fd.headWidth() > 0){
				headWidth = fd.headWidth();
			}
			if(fd.width() > 0){
				propertyWidth = fd.width();
			}
			if(!fd.formStyleClass().isEmpty()){
				tableClass = fd.formStyleClass();
			}
		}
	}
	
	@Override
	protected PropertyEditParser readProperty(UIPropertyAccessor descriptor) {
		PropertyEditor pe = descriptor.getAnnotation(PropertyEditor.class);
		if (null != pe && pe.ignoreCreate()) return null;
		PropertyInsert pc = descriptor.getAnnotation(PropertyInsert.class);
		if (null == pe && null == pc) return null;
		return new PropertyEditParser(this, descriptor, pe, pc);
	}
}
